﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace MvcEngine.Core.Validation
{
    /// <summary>
    /// The exception is thrown when a validation rule doesn't pass. 
    /// </summary>
    [Serializable]
    public class ValidationException : Exception
    {
        /// <summary>
        /// Gets or sets the broken rules.
        /// </summary>
        /// <value>The broken rules.</value>
        public IEnumerable<BrokenRule> BrokenRules { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        protected ValidationException()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        /// <param name="brokenRules">The broken rules.</param>
        public ValidationException(IEnumerable<BrokenRule> brokenRules)
            : base()
        {
            this.BrokenRules = brokenRules;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        /// <param name="brokenRule">The broken rule.</param>
        public ValidationException(BrokenRule brokenRule)
            : base()
        {
            this.BrokenRules = new List<BrokenRule>() { brokenRule };
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        /// <param name="message">Message to display.</param>
        /// <param name="brokenRules">The broken rules.</param>
        public ValidationException(string message, List<BrokenRule> brokenRules)
            : base(message)
        {
            this.BrokenRules = brokenRules;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        /// <param name="message">Message to display.</param>
        /// <param name="innerException">Inner exception of the exception.</param>
        /// <param name="brokenRules">The broken rules.</param>
        public ValidationException(string message, Exception innerException, List<BrokenRule> brokenRules)
            : base(message, innerException)
        {
            this.BrokenRules = brokenRules;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationException"/> class.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is null. </exception>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"/> is zero (0). </exception>
        protected ValidationException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }
    }
}
